import React, { Component } from 'react';
import TransSortTreeRef from '../../../refer/voucher/TransSortTreeRef';
import { base, createPage } from 'nc-lightapp-front';
const { NCModal, NCButton } = base;

class TransSortModal extends Component {
	constructor(props) {
		super(props);
		let defaultValue = this.props.defaultValue;
		this.state = {
			pk_transsort: '',
			transSortName: '',
			show: false,
		};
		if (defaultValue) {
			this.state.pk_transsort = defaultValue.pk_transsort;
			this.state.transSortName = defaultValue.transSortName;
		}
		// this.setState(state);
	}
	componentWillReceiveProps(nextProps) {
		if(nextProps.show == this.state.show){
            return;
        }
		this.setState({ show: nextProps.show });
		if(nextProps.show){
			this.props.modal.show('transsort');
		}else{
			this.props.modal.close('transsort');
		}
	}
	handleTransSortChange = (v) => {
		let { pk_transsort, transSortName } = this.state;
		if (v) {
			pk_transsort = v.refpk;
			transSortName = v.refname;
		} else {
			pk_transsort = '';
			transSortName = '';
		}
		this.setState({ pk_transsort, transSortName });
	};

	handleConfirm = () => {
		let { pk_transsort, transSortName } = this.state;
		this.props.onConfirm({ pk_transsort, transSortName });
	};
	handleClose = () => {
		this.setState({ show: false });
		this.props.onClose();
	};
	modalContent = () => {
		let { pk_transsort, transSortName } = this.state;
		let {pk_accountingbook} = this.props;
		return(
			<div className='accountingBookModal'>
				<span className='copy-lable'>{this.props.json['20020SDTRD-000027']/* 国际化处理： 结转档案分类*/}</span>
				<div className='refer-w'>
					<TransSortTreeRef
						fieldid='pk_transsort'
						value={{ refpk: pk_transsort, refname: transSortName }}
						onlyLeafCanSelect={true}
						queryCondition={{
							"isDataPowerEnable": 'Y',
							"DataPowerOperationCode" : 'fi',
							pk_accountingbook:pk_accountingbook
						}}
						onChange={this.handleTransSortChange}
					/>
				</div>
			</div>
		)
	}
	render() {
		let { modal, json } = this.props;
		return (
			<div>
				{modal.createModal('transsort', {
					title: json['20020SDTRD-000026'], /* 国际化处理： 转移到分类*/
					type:'senior',
					content: this.modalContent(), //弹框内容，可以是字符串或dom
					beSureBtnClick: this.handleConfirm,//点击确定按钮事件
					cancelBtnClick: this.handleClose, //取消按钮事件
					closeModalEve: this.handleClose, //关闭按钮事件回调
				})}
			</div>
		);
	}
}

TransSortModal = createPage({})(TransSortModal);
export default TransSortModal;
